<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <div class="layui-form-item">
        <label class="layui-form-label required">供应商名称</label>
        <div class="layui-input-block">
            <select name="supName" lay-filter="supplier" id="supplier" lay-verify="required">
                <%--如何实现供应商下拉选的动态渲染--%>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">商品名称</label>
        <div class="layui-input-block">
            <input type="text" name="goodsName"  lay-verify="required" lay-reqtext="商品名称不能为空" placeholder="请输入商品名称"
                   value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">支付类型</label>
        <div class="layui-input-block">
            <select lay-verify="required" name="payType">
                <option value=""></option>
                <option value="微信">微信</option>
                <option value="支付宝">支付宝</option>
                <option value="银行卡">银行卡</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">操作员</label>
        <div class="layui-input-block">
            <input type="text" name="operator" lay-verify="required" lay-reqtext="操作员不能为空" placeholder="请输入操作员" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">入库数量</label>
        <div class="layui-input-block">
            <input type="text" name="number" lay-verify="required" lay-reqtext="入库数量不能为空" placeholder="请输入销售数量" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">规格</label>
        <div class="layui-input-block">
            <input type="text" name="specs" lay-verify="required" lay-reqtext="规格不能为空" placeholder="请输入规格" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">入库价格</label>
        <div class="layui-input-block">
            <input type="text" name="price" lay-verify="required" lay-reqtext="销售价格不能为空" placeholder="请输入销售价格" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">入库时间</label>
        <div class="layui-input-block">
            <input type="date" name="importTime" class="layui-input" placeholder="请选择入库时间" lay-verify="required">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block required">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
<script src="/static/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;

        //1.查询供应商列表  渲染供应商下拉选
        $.get("/supplier/supList",function (res){
            var selectElem = $('select[name=supName]');
            var data = res.data;
            var optionsHtml = '<option value="">请输入供应商</option>';
            for (let i = 0; i < data.length; i++) {
                optionsHtml += '<option value="' + data[i].id + '">' + data[i].supName + '</option>';
            }
            selectElem.html(optionsHtml)
            // 调用 form.render() 方法重新渲染表单
            form.render('select');
        })

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            let studentJSON =  JSON.stringify(data.field)
            $.ajax({
                url:'/import/add',
                data:studentJSON,
                dataType:'json',
                type:'post',
                contentType:'application/json;charset=utf-8',
                success:function (res) {
                    if(res.code==0){
                        layer.msg(res.msg,{icon:1},function () {
                            // 关闭弹出层
                            var iframeIndex = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(iframeIndex);
                            // 重载表格
                            parent.layui.table.reload('currentTableId');
                        })
                    }else{
                        layer.msg(res.msg,{icon:2})
                    }
                }
            })
            return false;
        });
    });
</script>
</body>
</html>